#!/bin/bash

echo "盐碱地土壤质量评价系统 - 快速安装脚本"
echo "========================================"
echo

echo "检查环境..."
echo

# 检查Node.js
if ! command -v node &> /dev/null; then
    echo "错误: 未找到Node.js，请先安装Node.js 16+"
    exit 1
fi
echo "✓ Node.js 已安装"

# 检查Java
if ! command -v java &> /dev/null; then
    echo "错误: 未找到Java，请先安装JDK 8+"
    exit 1
fi
echo "✓ Java 已安装"

# 检查Maven
if ! command -v mvn &> /dev/null; then
    echo "错误: 未找到Maven，请先安装Maven 3.6+"
    exit 1
fi
echo "✓ Maven 已安装"

echo
echo "安装前端依赖..."
npm install
if [ $? -ne 0 ]; then
    echo "错误: 前端依赖安装失败"
    exit 1
fi
echo "✓ 前端依赖安装完成"

echo
echo "安装后端依赖..."
cd saline-alkali-soil-master
mvn install -DskipTests
if [ $? -ne 0 ]; then
    echo "错误: 后端依赖安装失败"
    exit 1
fi
cd ..
echo "✓ 后端依赖安装完成"

echo
echo "安装完成！"
echo
echo "下一步："
echo "1. 确保MySQL服务已启动"
echo "2. 创建数据库并导入表结构"
echo "3. 修改数据库连接配置"
echo "4. 运行 ./start-system.sh 启动系统"
echo
